#!/bin/sh
## vim: set expandtab tabstop=4 shiftwidth=4:
##
##
## (c) 2009 by Mike Walsh
##
## @author Mike Walsh <mike_walsh@mindspring.com>
## @package sandbox-lego
## @version $Revision$
## @lastmodified $Author$
## @lastmodifiedby $Date$
##
##
## Shell script to generate CSS color derivitives.  SuperFish
## menus are derived from the SuperFish source using a simple
## sed substitution of one color to another.  The theme CSS 
## files are generated similarly, starting from a baseline CSS
## file and replacing the placeholders with color values.
##
##

##  Define SuperFish menus CSS files

SUPERFISH="../js/superfish-1.4.8"
SUPERFISHCSS="${SUPERFISH}/css/superfish.css"
SUPERFISHNAVBARCSS="${SUPERFISH}/css/superfish-navbar.css"

##  Define theme CSS files

SANDBOXLEGOTHEMECSS="sandbox-lego.css"
SANDBOXLEGOTHEMEBGSMCSS="sandbox-lego-bg-small.css"
SANDBOXLEGOTHEMEBGLGCSS="sandbox-lego-bg-large.css"
SANDBOXLEGOTHEMELOGINBASELINECSS="sandbox-lego-login-baseline.css"
SANDBOXLEGOTHEMELOGINCSS="sandbox-lego-login.css"

##
##  Generate SuperFish Menu CSS
##
##  Superfish source Menu colors
##  #13a    - menu font color      param $2
##  #BDD2FF - menu color           param $3
##  #CFDEFF - hover color          param $4
##  #AABDE6 - sub-menu color       param $5
##  #D1DFFF - ? color              param $6
##  #E6EEFF - ? color              param $7
##  #9AAEDB - sub-sub-menu color   param $8
##  #fff    - border left color    param $9
##
function generate_superfish_css()
{
    if [ $# -ne 9 ]
    then
        echo "Usage:  `basename $0` - incorrect argument count"
        echo $@
        exit 1
    fi

    sed -e "s/#13a/$2/g" \
        -e "s/#BDD2FF/$3/g" \
        -e "s/#CFDEFF/$4/g" \
        -e "s/#AABDE6/$5/g" \
        -e "s/#D1DFFF/$6/g" \
        -e "s/#E6EEFF/$7/g" \
        -e "s/#9AAEDB/$8/g" \
        -e "s/#fff/$9/g" \
        ${SUPERFISHCSS} > `basename ${SUPERFISHCSS} .css`-$1.css
}

##
##  Generate login page CSS file
##
##  $1 - color scheme e.g. "red", "green", etc.
##  $2 - foreground color
##  $3 - default link color
##  $4 - login header background color
##  $5 - login button color
##  $6 - login button border color
##  $7 - login button hover border color
##
function generate_login_page_css()
{
    if [ $# -ne 7 ]
    then
        echo "Usage:  `basename $0` - incorrect argument count"
        echo $@
        exit 1
    fi

    sed -e "s/SBMT_LEGO_COLOR/$1/g" \
        -e "s/SBMT_FG_COLOR/$2/g" \
        -e "s/SBMT_BG_COLOR/$2/g" \
        -e "s/SBMT_DEFAULT_LINK_COLOR/$3/g" \
        -e "s/SBMT_LOGIN_HEADER_BG_COLOR/$4/g" \
        -e "s/SBMT_LOGIN_BUTTON_COLOR/$5/g" \
        -e "s/SBMT_LOGIN_BUTTON_BORDER_COLOR/$6/g" \
        -e "s/SBMT_LOGIN_BUTTON_HOVER_BORDER_COLOR/$7/g" \
        ${SANDBOXLEGOTHEMELOGINBASELINECSS} > `basename ${SANDBOXLEGOTHEMELOGINCSS} .css`-$1.css
}

##
##  Generate background CSS file
##
function generate_background_css()
{
    if [ $# -ne 3 ]
    then
        echo "Usage:  `basename $0` - incorrect argument count"
        echo $@
        exit 1
    fi

    sed -e "s/SBMT_BG_COLOR/$2/g" \
        -e "s/SBMT_FG_COLOR/$3/g" \
        -e "s/SBMT_LEGO_BRICK_COLOR/$1/g" \
        ${SANDBOXLEGOTHEMEBGSMCSS} > `basename ${SANDBOXLEGOTHEMEBGSMCSS} .css`-$1.css

    sed -e "s/SBMT_BG_COLOR/$2/g" \
        -e "s/SBMT_FG_COLOR/$3/g" \
        -e "s/SBMT_LEGO_BRICK_COLOR/$1/g" \
        ${SANDBOXLEGOTHEMEBGLGCSS} > `basename ${SANDBOXLEGOTHEMEBGLGCSS} .css`-$1.css
}

##
##  Generate foreground CSS file
##
function generate_foreground_css()
{
    if [ $# -ne 12 ]
    then
        echo "Usage:  `basename $0` - incorrect argument count"
        echo $@
        exit 1
    fi

    sed -e "s/SBMT_BG_COLOR/${11}/g" \
        -e "s/SBMT_FG_COLOR/$2/g" \
        -e "s/SBMT_MENU_BAR_COLOR/$6/g" \
        -e "s/SBMT_DEFAULT_LINK_COLOR/${12}/g" \
        -e "s/SBMT_DEFAULT_HEADING_COLOR/$5/g" \
        -e "s/SBMT_HEADER_HEADING_COLOR/$5/g" \
        -e "s/SBMT_LINK_COLOR/${12}/g" \
        -e "s/SBMT_DIV_BG_COLOR/${11}/g" \
        -e "s/SBMT_DIV_BORDER_COLOR/$5/g" \
        -e "s/SBMT_DIV_WRAPPER_COLOR/${11}/g" \
        -e "s/SBMT_DIV_HEADER_COLOR/$2/g" \
        -e "s/SBMT_DIV_FOOTER_COLOR/$5/g" \
        -e "s/SBMT_DIV_FOOTER_BG_COLOR/$2/g" \
        -e "s/SBMT_SIDEBAR_UL_BG_COLOR/$8/g" \
        -e "s/SBMT_SIDEBAR_UL_FG_COLOR/${10}/g" \
        -e "s/SBMT_SIDEBAR_UL_BORDER_COLOR/$5/g" \
        -e "s/SBMT_SIDEBAR_UL_DECOR_COLOR/$6/g" \
        -e "s/SBMT_SIDEBAR_DIV_BG_COLOR/$8/g" \
        -e "s/SBMT_SIDEBAR_DIV_FG_COLOR/$7/g" \
        -e "s/SBMT_ENTRY_TITLE_BG_COLOR/$8/g" \
        -e "s/SBMT_ENTRY_TITLE_FG_COLOR/$7/g" \
        -e "s/SBMT_ENTRY_TITLE_BORDER_COLOR/$4/g" \
        -e "s/SBMT_CALENDAR_BODY_COLOR/$9/g" \
        -e "s/SBMT_CALENDAR_HEAD_COLOR/$8/g" \
        -e "s/SBMT_CALENDAR_WEEKEND_FONT_COLOR/${10}/g" \
        -e "s/SBMT_ENTRY_META_BG_COLOR/$9/g" \
        -e "s/SBMT_ENTRY_META_FG_COLOR/$3/g" \
        -e "s/SBMT_ENTRY_META_BORDER_COLOR/$4/g" \
        -e "s/SBMT_SIDEBAR_LINK_BG_COLOR/$9/g" \
        -e "s/SBMT_SIDEBAR_LINK_FG_COLOR/$9/g" \
        -e "s/SBMT_SIDEBAR_DIV_BORDER_COLOR/$4/g" \
        -e "s/SBMT_LOGIN_HEADER_BG_COLOR/$4/g" \
        -e "s/SBMT_COMMENTS_DECOR_COLOR/$6/g" \
        -e "s/SBMT_CODE_FONT_COLOR/$6/g" \
        -e "s/SBMT_SUPERFISH_IE_FIX/${10}/g" \
        -e "s/SBMT_LEGO_BRICK_COLOR/$1/g" \
        ${SANDBOXLEGOTHEMECSS} > `basename ${SANDBOXLEGOTHEMECSS} .css`-$1.css
}

## Generate the red CSS scheme

##  $1 - red
##  $2 - #000000
##  $3 - #333333
##  $4 - #656565
##  $5 - #8A8A8A
##  $6 - #CA0000
##  $7 - #CDCDCD
##  $8 - #DDDDDD
##  $9 - #EFEFEF
##  $10 - #F66802
##  $11 - #FFFFFF
##  $12 - #F66802

echo "`basename $0`:  genetating red scheme"
generate_foreground_css "red" "#000000" "#333333" "#656565" \
    "#8A8A8A" "#CA0000" "#CDCDCD" "#DDDDDD" "#EFEFEF" \
    "#F66802" "#FFFFFF" "#F66802"
generate_background_css "red" "#FFFFFF" "#000000"
generate_login_page_css "red" "#FFFFFF" "#FF6802" "#656565" \
    "#8A8A8A" "DDDDDD" "#656565"
generate_superfish_css "red" "#FFFFFF" "#CA0000" \
    "#F66802" "#F99802" "#00FFFF" "#FF00FF" "#F99802" "#F66802"

## Generate the blue CSS scheme

##  $1 - blue
##  $2 - #000000
##  $3 - #333333
##  $4 - #656565
##  $5 - #8A8A8A
##  $6 - #003399
##  $7 - #CDCDCD
##  $8 - #DDDDDD
##  $9 - #EFEFEF
##  $10 - #505DD8
##  $11 - #FFFFFF
##  $12 - #F66802

echo "`basename $0`:  genetating blue scheme"
generate_foreground_css "blue" "#000000" "#333333" "#656565" \
    "#8A8A8A" "#003399" "#CDCDCD" "#DDDDDD" "#EFEFEF" \
    "#505DD8" "#FFFFFF" "#F66802"
generate_background_css "blue" "#FFFFFF" "#000000"
generate_login_page_css "blue" "#FFFFFF" "#003399" "#656565" \
    "#8A8A8A" "DDDDDD" "#656565"
generate_superfish_css "blue" "#FFFFFF" "#003399" \
    "#6485CA" "#99ABDD" "#00FFFF" "#FF00FF" "#99ABDD" "#DDDDDD"

## Generate the green CSS scheme

##  $1 - green
##  $2 - #000000
##  $3 - #333333
##  $4 - #656565
##  $5 - #8A8A8A
##  $6 - #2F6D2E
##  $7 - #CDCDCD
##  $8 - #DDDDDD
##  $9 - #EFEFEF
##  $10 - #669900
##  $11 - #FFFFFF
##  $12 - #F66802

echo "`basename $0`:  genetating green scheme"
generate_foreground_css "green" "#000000" "#333333" "#656565" \
    "#8A8A8A" "#2F6D2E" "#CDCDCD" "#DDDDDD" "#EFEFEF" \
    "#669900" "#FFFFFF" "#F66802"
generate_background_css "green" "#FFFFFF" "#000000"
generate_login_page_css "green" "#FFFFFF" "#F66802" "#656565" \
    "#8A8A8A" "DDDDDD" "#656565"
generate_superfish_css "green" "#FFFFFF" "#2F6D2E" \
    "#669900" "#336600" "#00FFFF" "#FF00FF" "#558000" "#00F001"

## Generate the yellow CSS scheme

##  $1 - yellow
##  $2 - #000000
##  $3 - #333333
##  $4 - #656565
##  $5 - #8A8A8A
##  $6 - #FFCD00
##  $7 - #CDCDCD
##  $8 - #DDDDDD
##  $9 - #EFEFEF
##  $10 - #FFB90A
##  $11 - #FFFFFF
##  $12 - #F66802

echo "`basename $0`:  genetating yellow scheme"
generate_foreground_css "yellow" "#000000" "#333333" "#656565" \
    "#8A8A8A" "#FFCD00" "#CDCDCD" "#DDDDDD" "#EFEFEF" \
    "#FFB90A" "#FFFFFF" "#F66802"
generate_background_css "yellow" "#FFFFFF" "#000000"
generate_login_page_css "yellow" "#FFFFFF" "#F66802" "#656565" \
    "#8A8A8A" "DDDDDD" "#656565"
generate_superfish_css "yellow" "#FFFFFF" "#FFCD00" \
    "#F5C314" "#FFA514" "#00FFFF" "#FF00FF" "#FFE100" "#00F001"

exit 0
